package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.awt.*;

public class Main extends Application implements Runnable {

    private Object primaryStage;

    @Override
    public synchronized void start(Stage primaryStage) throws Exception {
        //加载fxml文件
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
        primaryStage.setTitle("TCP环境监测系统");
        primaryStage.setScene(new Scene(root, 600, 400));
        primaryStage.show();
    }

    @Override
    public void run() {
        int len = 0;
        //开3个线程
        while (true) {
            if (len < 3) {
                len++;
                try {
                    start((Stage) primaryStage);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                break;
            }
        }
    }

    public static void main(String[] args) {
        //实现多线程
        Main main = new Main();
        Thread t1 = new Thread(main);
        Thread t2 = new Thread(main);

        t1.start();
        t2.start();
        System.out.println("线程1启动");
        launch(args);


    }


}
